#include <QMutex>
#include "abstract-result.h"

AbstractResult::AbstractResult(QObject *parent) :
    QObject(parent), m_mutex(new QMutex(QMutex::Recursive))
{
}

AbstractResult::~AbstractResult()
{
    delete m_mutex;
}

bool AbstractResult::hasError() const
{
    QMutexLocker lock(m_mutex);
    return m_error.isValid();
}

ResultError AbstractResult::error() const
{
    QMutexLocker lock(m_mutex);
    return m_error;
}

QVariant AbstractResult::requestData() const
{
    QMutexLocker lock(m_mutex);
    return m_requestData;
}

void AbstractResult::setError(const QString &errorText, int errorCode)
{
    QMutexLocker lock(m_mutex);
    m_error = ResultError(errorText, errorCode);
    emitResultReady();
}

void AbstractResult::setError (const ResultError& error)
{
    QMutexLocker lock(m_mutex);
    m_error = error;
    emitResultReady();
}

void AbstractResult::setRequestData(const QVariant& requestData)
{
    QMutexLocker lock(m_mutex);
    m_requestData = requestData;
}
